package org.jsbd.boss.action;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.jsbd.boss.domian.UmRetentConfig;
import org.jsbd.boss.domian.channel.ChannelRetentConfig;
import org.jsbd.boss.service.IUmRetentConfigService;
import org.jsbd.boss.common.DataGridModel;
import org.jsbd.boss.common.ResponseMapUtils;
import org.jsbd.boss.common.ResponseUtils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/umRetentConfig")
public class UmRetentConfigController {

	public static final Logger logger = LoggerFactory.getLogger(UmRetentConfigController.class);

	@Autowired
	private IUmRetentConfigService umRetentConfigService;

	@RequestMapping(value = "list", method = RequestMethod.GET)
	public String list(Model model) {
		return "umRetentConfig/list";
	}

	@RequestMapping(value = "save", method = RequestMethod.POST)
	@ResponseBody
	public Object save(@RequestBody UmRetentConfig[] list, HttpServletResponse response) {
		umRetentConfigService.save(Arrays.asList(list));
		return ResponseMapUtils.responseSuccess();
	}

	@RequestMapping(value = "getListPage")
	@ResponseBody
	public Map<String, Object> getListPage(DataGridModel page, UmRetentConfig umRetentConfig) throws Exception {
		if (umRetentConfig.getAppInfoId() == null || umRetentConfig.getChannel() == null) {
			return null;
		}
		return umRetentConfigService.getListPage(page, umRetentConfig);
	}

	@RequestMapping(value = "/delete", method = RequestMethod.POST)
	public void delete(Integer[] ids, HttpServletResponse response) {
		try {
			List<Integer> list = Arrays.asList(ids);
			umRetentConfigService.delete(list);
			ResponseUtils.responseSuccess(response);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			ResponseUtils.responseFailure(response);
		}
	}
}